package org.lgiavedoni.android.franq.util.timer;

import java.util.Timer;

import org.lgiavedoni.android.franq.core.cron.CronTask;
import org.lgiavedoni.android.franq.core.cron.RepetibleCron;
import org.lgiavedoni.android.franq.core.prediction.PredictionTimerTask;

public class TimerUtil {

	public static void addCron(Timer timer, CronTask cronTask) {
		if (cronTask instanceof RepetibleCron)
			timer.scheduleAtFixedRate(cronTask, cronTask.getDelay(), ((RepetibleCron) cronTask).getPeriod());
		else
			timer.schedule(cronTask, cronTask.getDelay());
	}

	public static void addPrediction(Timer timer, PredictionTimerTask pTimerTask) {
		timer.schedule(pTimerTask, pTimerTask.getPrediction().getPredictedDate());
	}

	public static void purge(Timer timer) {
		timer.purge();
	}
}
